package org.noip.amdg;

import java.awt.Font;
import java.awt.Graphics;
import java.awt.font.TextAttribute;
import java.text.AttributedString;

public class WinAnimation implements Animation {

	private static final int STEP_TIME = 10;
	private static final int MAX_X = 700;
	private static final int MAX_Y = 550;
	private final AttributedString win = new AttributedString("YOU WIN!");
	
	private int currentX = 0;
	private int currentY = 30;
	private long lastTime;
	
	public WinAnimation() {
		win.addAttribute(TextAttribute.FONT, new Font("Sans", Font.BOLD, 28));
	}
	
	public int getStepTime() {
		return STEP_TIME;
	}

	public boolean isDone() {
		return currentX >= MAX_X && currentY >= MAX_Y;
	}

	public void renderFrame(Graphics graphics) {
		long currentTime = System.currentTimeMillis();
		if (currentTime - lastTime >= STEP_TIME) {
			if (currentX >= MAX_X) {
				if (currentY < MAX_Y) {
					currentY++;
				}
			} else {
				currentX++;
			}
			
			lastTime = currentTime;
		}
		
		graphics.drawString(win.getIterator(), currentX, currentY);
	}

}
